<?php
/**
 * 微博后台管理项目 媒体表数据层

 */
define("CACHE_MBLOG_COUNT_RT_TOP","mblog_rt_count_");
class db_mblog_rt_count extends db_base
{
	var $table_name  ="mblog_rt_count";
	
	
	
	
	
	/**
	 * 根据D_ID取数据
	 * @param $d_id
	 */
	function get_mblog_list_by_mid_order_by_rtnum($mid,$p=1,$count=20)
	{
		$key = CACHE_MBLOG_COUNT_RT_TOP . "-order_by_rtnum-{$mid}-{$p}-{$count}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " mid = '{$mid}' and status =1  ";
			$content = $this->get_alllist($this->table_name,$p,$count, "reposts_count desc,comments_count desc", $where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	/**
	 * 根据D_ID取数据
	 * @param $d_id
	 */
	function get_mblog_list_by_mid_order_by_cmnum($mid,$p=1,$count=20)
	{
		
		$key = CACHE_MBLOG_COUNT_RT_TOP . "-order_by_cmnum-{$mid}-{$p}-{$count}";
		
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " mid = '{$mid}' and status =1  ";
			$content = $this->get_alllist($this->table_name,$p,$count, "comments_count desc",$where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	
	function get_mblog_count_by_mid($mid)
	{
		
		$key = CACHE_MBLOG_COUNT_RT_TOP . "-get_mblog_count_by_mid-{$mid}";
		
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " mid = '{$mid}' and status =1  ";
			$content = $this->get_listcount($this->table_name,$where);
			$mc->set($key, serialize($content), 0, CACHE_TIME_MBLOG_COUNT_RT_TOP);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	
	
	function cron_get_list_by_mid_order_by_rt_num($mid,$p,$pcount)
	{
		$where = " mid = '{$mid}' and status =1  ";
		$content = $this->get_alllist($this->table_name,$p,$pcount, "reposts_count desc",$where);
		return $content;
	}
	
	
	
	function cron_get_list_by_mid($mid,$p,$pcount)
	{
		$where = " mid = '{$mid}' and status =1  ";
		$content = $this->get_alllist($this->table_name,$p,$pcount, "",$where);
		return $content;
	}

	
	function cron_get_count_by_mid($mid)
	{
		$where = " mid = '{$mid}' and status =1  ";
		$content = $this->get_listcount($this->table_name,$where);
		return $content;	
	}
	
	function cron_update_count_by_status_id($status_id,$comments_count="",$reposts_count="")
	{
		$where = "status_id = $status_id";
		$ary = array();

		if(strlen($comments_count)>0)$ary["comments_count"] = $comments_count;
		if(strlen($reposts_count)>0)$ary["reposts_count"] = $reposts_count;
		
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
		
	}
	
	function cron_get_min_status_id_by_mid($mid)
	{
		
		$where = " mid = '{$mid}' and status =1  ";
		$content = $this->get_alllist($this->table_name,1,1, "status_id",$where);
		
		return $content[0];
		
	}
	
	function cron_get_max_status_id_by_mid($mid)
	{
		
		$where = " mid = '{$mid}' and status =1  ";
		$content = $this->get_alllist($this->table_name,1,1, "status_id desc",$where);
		
		return $content[0];
		
	}
	
}
